package com.ysd.lis.service.eq.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.WkKnowledgeContent;
import com.ysd.lis.entity.WkKnowledgeIssue;
import com.ysd.lis.entity.eq.EqPatrolTask;
import com.ysd.lis.entity.eq.EqPatrolTaskEq;
import com.ysd.lis.entity.eq.EqPatrolTaskEqSt;
import com.ysd.lis.mapper.eq.EqPatrolTaskEqMapper;
import com.ysd.lis.service.eq.EqPatrolTaskEqService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 巡检任务设备 服务实现类
 * </p>
 *
 * @author WH
 * @since 2024-08-15
 */
@Service
public class EqPatrolTaskEqServiceImpl extends ServiceImpl<EqPatrolTaskEqMapper, EqPatrolTaskEq> implements EqPatrolTaskEqService {

    @Autowired
    EqPatrolTaskEqMapper eqPatrolTaskEqMapper;
    @Override
    public Result findPatrolTaskEqList(EqPatrolTaskEq eqPatrolTaskEq) {
        MPJLambdaWrapper<EqPatrolTaskEq> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.distinct();
        queryWrapper.selectAll(EqPatrolTaskEq.class);
        queryWrapper.selectCollection(EqPatrolTaskEqSt.class, EqPatrolTaskEq::getPatrolTaskEqStList);
        queryWrapper.leftJoin(EqPatrolTaskEqSt.class, EqPatrolTaskEqSt::getTaskEqId, EqPatrolTaskEq::getId);

        queryWrapper.eq(StringUtils.isNotBlank(eqPatrolTaskEq.getTaskId()),EqPatrolTaskEq::getTaskId,eqPatrolTaskEq.getTaskId());
        queryWrapper.eq(EqPatrolTaskEq::getDelFlag,0);
        List<EqPatrolTaskEq> eqPatrolTaskEqs = eqPatrolTaskEqMapper.selectJoinList(EqPatrolTaskEq.class, queryWrapper);
        return Result.succ(1, "查询成功！", eqPatrolTaskEqs);
    }

    @Override
    public Result findPatrolTaskByEqId(EqPatrolTaskEq eqPatrolTaskEq) {
        MPJLambdaWrapper<EqPatrolTaskEq> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.distinct();
        queryWrapper.selectAll(EqPatrolTaskEq.class);
        queryWrapper.selectAs(EqPatrolTask::getName,EqPatrolTaskEq::getTaskName);
        queryWrapper.selectCollection(EqPatrolTaskEqSt.class, EqPatrolTaskEq::getPatrolTaskEqStList);
        queryWrapper.leftJoin(EqPatrolTask.class, EqPatrolTask::getId, EqPatrolTaskEq::getTaskId);
        queryWrapper.leftJoin(EqPatrolTaskEqSt.class, EqPatrolTaskEqSt::getTaskEqId, EqPatrolTaskEq::getId);

        queryWrapper.eq(EqPatrolTaskEq::getEqId,eqPatrolTaskEq.getEqId());
        queryWrapper.eq(EqPatrolTaskEq::getDelFlag,0);
        List<EqPatrolTaskEq> eqPatrolTaskEqs = eqPatrolTaskEqMapper.selectJoinList(EqPatrolTaskEq.class, queryWrapper);
        return Result.succ(1, "查询成功！", eqPatrolTaskEqs);
    }
}
